package com.ruoyi.web.controller.marketing;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marketing.domain.MarketingActivity;
import com.ruoyi.marketing.service.IMarketingActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 营销页面Controller
 *
 * @author hao
 * @date 2023-01-28
 */
@RestController
@RequestMapping("/marketing/activity")
public class MarketingActivityController extends BaseController
{
    @Autowired
    private IMarketingActivityService marketingActivityService;

    /**
     * 查询营销页面列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(MarketingActivity marketingActivity)
    {
        startPage();
        List<MarketingActivity> list = marketingActivityService.selectMarketingActivityList(marketingActivity);
        return getDataTable(list);
    }

    /**
     * 导出营销页面列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:activity:export')")
    @Log(title = "营销页面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MarketingActivity marketingActivity)
    {
        List<MarketingActivity> list = marketingActivityService.selectMarketingActivityList(marketingActivity);
        ExcelUtil<MarketingActivity> util = new ExcelUtil<MarketingActivity>(MarketingActivity.class);
        util.exportExcel(response, list, "营销页面数据");
    }

    /**
     * 获取营销页面详细信息
     */
    @PreAuthorize("@ss.hasPermi('marketing:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return AjaxResult.success(marketingActivityService.getById(activityId));
    }

    /**
     * 新增营销页面
     */
    @PreAuthorize("@ss.hasPermi('marketing:activity:add')")
    @Log(title = "营销页面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MarketingActivity marketingActivity)
    {
        return toAjax(marketingActivityService.save(marketingActivity));
    }

    /**
     * 修改营销页面
     */
    @PreAuthorize("@ss.hasPermi('marketing:activity:edit')")
    @Log(title = "营销页面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MarketingActivity marketingActivity)
    {
        return toAjax(marketingActivityService.updateById(marketingActivity));
    }

    /**
     * 删除营销页面
     */
    @PreAuthorize("@ss.hasPermi('marketing:activity:remove')")
    @Log(title = "营销页面", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(marketingActivityService.removeBatchByIds(Arrays.asList(activityIds)));
    }
}
